/*
 * bmp_encoder.c
 *
 *  Created on: 2012-12-2
 *      Author: seemrain
 */

#include "bmp_encoder.h"
#include <string.h>
#include <stdlib.h>

BITMAPFILEHEAD fbmphead;
BITMAPINFOHEADER fbmpinfo;

BMPINFO *bmp_getinfo(unsigned char *header)
{

	static BMPINFO  info;
	unsigned int head_size = 40;

	memcpy((unsigned char *)&fbmphead,header,14);
	memcpy((unsigned char *)&fbmpinfo,&header[14],head_size);
	if((fbmphead.magic[0] != 'B') && (fbmphead.magic[1] != 'M'))
		return 0;
	if(fbmpinfo.height<0)
		info.order = 0;
	else
		info.order = 1;
	info.bpp = fbmpinfo.bitspp;
	info.width = abs(fbmpinfo.width);
	info.height = abs(fbmpinfo.height);
	info.pixel_array = (unsigned char *)((unsigned int)header + fbmphead.bmp_offset);
	if(((info.width & 1) == 1) && info.bpp == 16)
		info.stuff = 1;
	else
		info.stuff = 0;
	return &info;
}
